function submitbutton(action)
{
	document.getElementById('cmd').value = action;
	document.adminForm.submit();
}

function createAction(url)
{
	window.location = url;
}

function updateAction(url)
{
	if(!hasCheck())
	{
		alert("You shoud select one item to edit");
		return false;
	}
	var id = getFirstCheck();
	url += "/id/"+id;
	window.location = url;
}

function deleteAction()
{
	if(!hasCheck())
	{
		alert("You shoud select one item to delete");
		return false;
	}
	
	if(!confirm("Do you want to delete all selected items?"))
	{
		return false;
	}
	submitbutton('delete');
}

function saveAction()
{
	submitbutton('save');
}

function cancelAction(url)
{
	window.location = url;
}

function getFirstCheck()
{
	return $(".chkBox:checked").eq(0).val();
}

function hasCheck()
{
	return ($(".chkBox:checked").size() > 0);
}

function checkAll()
{
	if($(".chkBox:checked").size() == $(".chkBox").size())
		$(".chkBox").attr("checked",false);
	else
		$(".chkBox").attr("checked",true);
}

function sort(orderBy,orderDirection)
{
	$("#params").val(orderBy+";"+orderDirection);
	submitbutton('sort');
}

function searchAction()
{
	submitbutton('search');
}

function changePage()
{
	submitbutton('search');
}

function publish(status,id)
{
	$("#params").val(status+";"+id);
	submitbutton('publish');
}

function saveOrders()
{
	var params= "";
	for(var i=0; i< $(".chkBox").size(); i++)
	{		
		var idItem = $(".chkBox").eq(i).val();
		var orderItem = $(".order").eq(i).val();
		params += idItem + "," + orderItem + ";";
	}
	$("#params").val(params);
	submitbutton('saveOrders');
}

function changeOrder(id1, id2)
{
	if(id1 == id2)return false;
	$("#params").val(id1 + ";" +id2);
	submitbutton('saveorders');
}

function moveUp(count)
{
	var id = $("#item"+count).val();
	count --;
	var oid = $("#item"+count).val();
	if(oid == null)return;
	$("#params").val(id + ";" +oid);
	submitbutton('changeOrder');
}

function moveDown(count)
{
	var id = $("#item"+count).val();
	count ++;
	var oid = $("#item"+count).val();
	if(oid == null)return;
	$("#params").val(id + ";" +oid);
	submitbutton('changeOrder');
}

function changeCategory()
{
	submitbutton('changeCategory');
}

function initMCE(elements,width,height)
{
	if(!width)
	{
		width = "100%";
	}
	if(!height)
	{
		height = "500";
	}
	tinyMCE.init({
		// General options
		mode : "exact",
		elements : elements,
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		width : width,
		height : height,

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "misc/mce/css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "misc/mce/lists/template_list.js",
		external_link_list_url : "misc/mce/lists/link_list.js",
		external_image_list_url : "misc/mce/lists/image_list.js",
		media_external_list_url : "misc/mce/lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});

}